package huaweiod.first;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * 华为OD机试真题 Java 实现【密室逃生游戏】【2022.11 Q4 新题】
 * abc
 * sdf134 A2c4b
 * 2
 *
 * abc
 * sdf134 A2c4bd 523[]
 * -1
 */
public class A_2023_51_EscapeRoomGame {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String pwd = in.nextLine();
        List<String> boxes = Arrays.stream(in.nextLine().split(" "))
                .map(A_2023_51_EscapeRoomGame::filterString)
                .collect(Collectors.toList());
        for (int i = 0; i < boxes.size(); i++) {
            if (pwd.equals(boxes.get(i).toLowerCase())) {
                System.out.println(i + 1);
                break;
            }
            if (i == boxes.size() - 1) {
                System.out.println("-1");
            }
        }
    }

    public static String filterString(String str) {
        char[] chars = str.toCharArray();
        LinkedList<Character> tempChars = new LinkedList<>();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
                tempChars.add(c);
            }
        }
        tempChars.sort((a, b) -> a - b);
        String res = "";
        for (Character tempChar : tempChars) {
            res += tempChar;
        }
        return res;
    }
}
